#define _CRT_SECURE_NO_WARNINGS
#include<stdlib.h>
#include<stdio.h>
double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size)
{
    int len = nums1Size + nums2Size;
    int* num = malloc(sizeof(int) * len);
    int i = 0;
    int j = 0;
    int n = 0;
    int flag = 0;
    if (nums1Size && nums2Size)
    {
        for (n = 0; n < len; n++)
        {
            if (nums1[i] < nums2[j])
            {
                num[n] = nums1[i];
                i++;
                if (i == nums1Size)
                {
                    flag = 1;
                    n++;
                    break;
                }
            }
            else
            {
                num[n] = nums2[j];
                j++;
                if (j == nums2Size)
                {
                    n++;
                    break;
                }
            }
        }
        if (flag)
        {
            for (; j < nums2Size; j++)
            {
                num[n] = nums2[j];
                n++;
            }
        }
        else
        {
            for (; i < nums1Size; i++)
            {
                num[n] = nums1[i];
                n++;
            }
        }
    }
    else if (nums1Size == 0 && nums2Size)
    {
        if (nums2Size % 2)
        {
            return (double)nums2[(nums2Size - 1) / 2];
        }
        else
        {
            return (nums2[nums2Size / 2 - 1] + nums2[nums2Size / 2]) / (double)2;
        }
    }
    else
    {
        if (nums1Size % 2)
        {
            return (double)nums1[(nums1Size - 1) / 2];
        }
        else
        {
            return (nums1[nums1Size / 2 - 1] + nums1[nums1Size / 2]) / (double)2;
        }
    }
    if (len % 2)
    {
        return (double)num[(len - 1) / 2];
    }
    else
    {
        return (num[len / 2 - 1] + num[len / 2]) / (double)2;
    }
}
int main()
{
    int num1 = 2;
    int num2 = 1;
    int nums1[2] = { 1,2 };
    int nums2[1] = { 3 };
    printf("%lf",findMedianSortedArrays(nums1, num1, nums2, num2));
    return 0;
}